package com.example.shushiyunsst.fragment.main.home.child.miner22

import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import com.alibaba.fastjson.JSON
import com.example.library_common.album.utils.Utils
import com.example.library_common.base.BaseFragmentEx
import com.example.library_common.networking.RestClient
import com.example.library_common.utils.ShUtils
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.home.child.miner22.bean.ToCountListHeaderBean
import com.example.wallet.db.UserInfoManager
import com.example.wallet.utils.selectorIcon

class ToCountFragment : BaseFragmentEx(),ToCountListener {

    companion object {
        fun newInstance(): ToCountFragment {
            val args = Bundle()
            val fragment = ToCountFragment()
            fragment.arguments = args
            return fragment
        }
    }

    private lateinit var totalIncome :TextView
    private lateinit var myTotalIncome :TextView
    private lateinit var mySpreadIncome :TextView
    private lateinit var myShareIncome :TextView
    private lateinit var bestHave :TextView
    private lateinit var titleTemplate :TextView
    private lateinit var leastHolder:TextView

    override fun getLayoutId(): Any {
        return R.layout.to_count_fragment
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        titleTemplate=view.findViewById(R.id.title_template)
        titleTemplate.text=_mActivity.getString(R.string.util_all,selectorIcon())

        leastHolder=view.findViewById(R.id.least_holder)
//        leastHolder.text=_mActivity.getString(R.string.at_lest_holder_on,selectorIcon())

        totalIncome=view.findViewById(R.id.totalIncome)
        myTotalIncome=view.findViewById(R.id.myTotalIncome)
        mySpreadIncome=view.findViewById(R.id.mySpreadIncome)
        myShareIncome=view.findViewById(R.id.myShareIncome)
        bestHave=view.findViewById(R.id.bestHave)

        val mToolbar: Toolbar = view.findViewById(R.id.mToolbar)
        mToolbar.navigationIcon =
            ShUtils.tintDrawable(
                R.drawable.ic_round_arrow_left_black_24,
                ContextCompat.getColor(
                    _mActivity, R.color.bg_color
                )
            )

        mToolbar.setTitleTextColor(
            ContextCompat.getColor(
                _mActivity, R.color.bg_color
            )
        )

        mToolbar.title = "矿池"

        mToolbar.inflateMenu(R.menu.to_count_men)

        mToolbar.setOnMenuItemClickListener {

            when(it.itemId){
                R.id.detail->{
                    start(SouYiDetailFragment.newInstance())
                }
            }

              false
        }

        mToolbar.setNavigationOnClickListener { onBackPressedSupport() }
        val newInstance = ToCountListFragment.newInstance()
        newInstance.setToCountListener(this)
        loadRootFragment(R.id.mRFrameLayout,newInstance  )


    }

    override fun setToCount(headerBean: ToCountListHeaderBean?) {
        totalIncome.text = headerBean?.totalIncome
        myTotalIncome.text = headerBean?.myTotalIncome
        mySpreadIncome.text = headerBean?.mySpreadIncome
        bestHave.text = headerBean?.bestHave
        leastHolder.text=_mActivity.getString(R.string.at_lest_holder_on22,headerBean?.minCostIncome,selectorIcon())

    }
}